package main

import (
	"net/http"
	"os"
)

var home string		// home dir
var recipeFile string
var recp *RecipeList


func main() {
	getDefaults()

	// load database
	var err error
	recp, err = readRecipeList()
	if err != nil {
		panic(err)
	}

	initializeServer()
}


func getDefaults() {
	home = os.Getenv("HOME");
	os.Mkdir(os.Getenv("HOME") + "/.recp", 0777)
	recipeFile = home + "/.recp/recipes.txt"
}


func initializeServer() {
	http.Handle("/", http.HandlerFunc(serveIndex))
	http.Handle("/local/", http.HandlerFunc(serveLocal))
	http.Handle("/recipe/", http.HandlerFunc(serveRecipe))
	http.Handle("/add/", http.HandlerFunc(serveAdd))
        http.Handle("/save/", http.HandlerFunc(serveSave))
	err := http.ListenAndServe("0.0.0.0:8080", nil)
	panic(err)
}
